home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3151 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  51 lines

  1. Path: zetnet.co.uk!demon!stsdaveb.demon.co.uk
  2. From: dave@stsdaveb.demon.co.uk (Dave Thornton)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Accessing UNIX environment variables with C
  5. Date: Fri, 26 Jan 1996 15:28:08 GMT
  6. Organization: Severn Trent Systems
  7. Message-ID: <3108f268.14258749@news.demon.co.uk>
  8. References: <4eaqt5$f23@zippy.cais.net>
  9. NNTP-Posting-Host: stsdaveb.demon.co.uk
  10. X-NNTP-Posting-Host: stsdaveb.demon.co.uk
  11. X-Newsreader: Forte Agent .99c/16.141
  12.  
  13. On 26 Jan 1996 15:10:29 GMT, usaid@cais.cais.com (USAID) wrote:
  14.  
  15. >Can someone tell me how to use a UNIX environment variable in C?  The 
  16. >equivalent statement in Perl is the %ENV{VARNAME} statement, where 
  17. >VARNAME is the environment variable.
  18. >
  19. >Thanks for your help.
  20. >
  21. >Jed Prentice
  22.  
  23.  
  24. I think its the standard ANSI C function  getenv();
  25.  
  26. /*   Example for getenv  */
  27.  
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30.  
  31. void main ()
  32. {
  33.    char *path;
  34.    
  35.    path = getenv ("PATH");
  36.    if (path == NULL)
  37.       fprintf (stderr, "No PATH set\n");
  38.    else
  39.       printf ("PATH=%s\n", path);
  40. }
  41.  
  42. Its a long time since I worked on Unix machines but I think this is
  43. how its done..
  44.  
  45. Regards 
  46.  
  47. -------------------------------------------------------------------------------
  48. | Dave Thornton    | email dave@stsdaveb.demon.co.uk                          |
  49. | Staffs, England  |                                                          |
  50. -------------------------------------------------------------------------------
  51.